<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>mytestAdmin</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="./css/font.css">
		<link rel="stylesheet" href="./css/xadmin.css">
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="./js/xadmin.js"></script>
		<script src="js/config.js" type="application/javascript"></script>
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
	</head>

	<body>

		<div class="x-body">
			<script type="text/html" id="toolbarDemo">
				<button class="layui-btn" onclick="fresh()"><i class="layui-icon">ဂ</i></button>
				<button class="layui-btn" onclick="add()"><i class="layui-icon">&#xe608;</i> 添加</button>
			</script>
			<table class="layui-hide" id="jobList" lay-filter="jobList"></table>
		</div>
		<script type="text/html" id="action">
			<div class="layui-btn-group">
				<a title="编辑" class="layui-btn layui-btn-xs layui-btn-primary" lay-event="edit">
					<i class="layui-icon">&#xe642;</i>
				</a>
				<a title="删除" class="layui-btn layui-btn-xs layui-btn-primary" lay-event="del">
					<i class="layui-icon">&#xe640;</i>
				</a>
			</div>
		</script>
		<script>
			layui.use('table', function() {
				var table = layui.table;

				table.render({
					elem: '#jobList', headers: {token: username,projectid: projectid},
					url: base_url + '/testcaseapi/getapilist',
					cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
					page: true,
					toolbar: '#toolbarDemo',
					cols: [
						[{
							field: 'method',
							width: 100,
							title: '请求方式'
						}, {
							field: 'url',
							width: 300,
							title: '请求地址',
						}, {
							field: 'inserttime',
							title: '创建时间'
						}, {
							field: 'username',
							title: '创建人'
						}, {
							field: 'projectname',
							title: '所属项目'
						}, {
							fixed: 'right',
							title: '操作',
							toolbar: '#action',
							width: 110
						}]
					]
				});

				//监听行工具事件
				table.on('tool(jobList)', function(obj) {
					var data = obj.data;
					if(obj.event === 'del') {
						parent.layer.confirm('确定要删除此接口吗？', function(index) {
							$.ajax({
								url: base_url + '/testcaseapi/delapi/' + data.id,
								type: 'get',
								data: {},
								dataType: 'json',
								success: function(result) {
									if(result.code == '0') {
										layer.msg('执行成功');
										location.replace(location.href);
									} else {
										layer.msg(result.msg);
									}
								}
							});
							parent.layer.close(index);
						});
					} else if(obj.event === 'edit') {
						parent.layer.open({
							type: 2,
							title: '接口(' + data.url + ')',
							area: ['1000px', '400px'],
							maxmin: true,
							content: ['editapi.html#/id=' + data.id, 'yes'],
							end: function() {
								location.reload();
							}
						});
					}
				});

			});
		</script>
		<script>
			function add() {
				var ss = parent.layer.open({
					type: 2,
					title: '接口添加',
					area: ['1000px', '400px'],
					maxmin: true,
					content: ['addapi.html', 'yes'],
					end: function() {
						location.reload();
					}
				});
			}
		</script>
	</body>

</html>